package cn.est.controller;

import cn.est.pojo.Users;
import cn.est.utils.RedisUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestRedisController {

    @Autowired
    RedisUtil redisUtils;

    @RequestMapping(value = "/setredis",method = RequestMethod.GET)
    public Object setRedis(){
        Users users = new Users();
        users.setUserName("周杰伦");
        users.setAccount("888");
        redisUtils.set("zhoujielun4", users);
        return  "创建用户成功";
    }

    @RequestMapping(value = "/getredis",method = RequestMethod.GET)
    public Object getRedis(){

        return redisUtils.get("zhoujielun4");
    }

    @ApiOperation(value = "获取所有用户",notes = "获取所有用户信息",httpMethod = "GET")
    @RequestMapping(value = "/allusers",method = RequestMethod.GET)
    public Object getAllUser(){
        return "获取所有用户";
    }

    @ApiOperation(value = "根据id获取用户",notes = "根据id获取用户信息",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "用户ID",required = true,dataType = "int")
    })
    @RequestMapping(value = "/userbyid",method = RequestMethod.GET)
    public Object getUserById(@RequestParam(value = "id",required = true) Integer id){
        return "获取 id 的用户信息";
    }
}
